package com.awonsome.admin.boot.controller;

import com.awonsome.admin.boot.pojo.entity.SysUser;
import com.awonsome.admin.boot.service.ISysUserService;
import com.awonsome.common.core.result.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangdejun
 * @date 2022/1/23 23:00
 */
@RestController
@RequestMapping(value = "/api/v1/users")
@RequiredArgsConstructor
public class UserController {

    private final ISysUserService iSysUserService;

    /**
     * 分页查询用户
     *
     * @param page
     * @param limit
     * @param nickname
     * @param mobile
     * @param status
     * @param deptId
     * @return
     */
    @GetMapping
    public Result list(Integer page, Integer limit, String nickname, String mobile, Integer status, Long deptId) {
        SysUser user = new SysUser();
        user.setNickname(nickname);
        user.setMobile(mobile);
        user.setStatus(status);
        user.setDeptId(deptId);
        IPage<SysUser> result = iSysUserService.list(new Page<>(page, limit), user);
        return Result.success(result.getRecords(), result.getTotal());
    }

}
